import { webAxiosCreate } from 'app'
import qs from 'qs';
import * as Params from './query'
export * from './query'

// 业务服务上下文
const context = import.meta.env.DEV ? '/huqiyao/web' : import.meta.env.API_CONTEXT;

/**************************************************************************************************/
/*************************************数据准备-数据源基本信息管理************************************/
/**************************************************************************************************/
const AxiosDataPreparation = webAxiosCreate({
    paramsSerializer: params => qs.stringify(params, { arrayFormat: 'brackets' }),
    baseURL: `${context}/dataPreparation`
})
export namespace ResponseDataPreparation {
    // 分类管理团队列表接口
    export interface CatalogueListTeam {
        label: string;
        organizationTeamUserId: string;
        teamName: string;
        configType: string;
        creatTime: string;
        updateTime: string;
        valiFlag: number;
    }

    // 数据源信息接口
    export interface DataSourceInfo {
        dataPreparationSourceId: string;
        teamId: string;
        dataPreparationSourceName: string;
        preparationSourceDesc: string;
        dataPreparationSourceType: string;
        ipAddress: string;
        port: number;
        accountName: string;
        password: string;
        creatTime: string;
        updateTime: string;
        valiFlag: number;
    }

    // 分页接口
    export interface PaginationResponse {
        records: DataSourceInfo[];
        total: number;
        size: number;
        current: number;
        orders: any[];
        searchCount: boolean;
        pages: number;
    }

    // 数据库驱动类型选项接口
    export interface DriverTypeOption {
        label: string;
        value: string;
    }
}
export const ApiDataPreparation = {
    // 分类管理团队列表
    catalogueList() {
        return AxiosDataPreparation.request<any, ResponseDataPreparation.CatalogueListTeam[]>({
            url: '/catalogueList',
            method: 'GET',
            headers: { 'Content-Type': 'application/json' }
        })
    },
    // 查询
    list(data: Params.ParamDataPreparationList) {
        return AxiosDataPreparation.request<any, ResponseDataPreparation.PaginationResponse>({
            url: '/list',
            method: 'POST',
            data: Object.assign({}, data),
            headers: { 'Content-Type': 'application/json' }
        })
    },
    // 授权给我
    authGiveMe(data: Params.ParamDataPreparationList) {
        return AxiosDataPreparation.request<any, ResponseDataPreparation.PaginationResponse>({
            url: '/authGiveMe',
            method: 'POST',
            data: Object.assign({}, data),
            headers: { 'Content-Type': 'application/json' }
        })
    },
    // 数据源驱动类型
    driverType() {
        return AxiosDataPreparation.request<any, ResponseDataPreparation.DriverTypeOption[]>({
            url: '/driverType',
            method: 'GET',
            headers: { 'Content-Type': 'application/json' }
        })
    },
    // /web/dataPreparation/add
    add(data: Params.ParamDataPreparationAdd) {
        return AxiosDataPreparation.request({
            url: '/add',
            method: 'POST',
            data: Object.assign({}, data),
            headers: { 'Content-Type': 'application/json' }
        })
    },
    // /web/dataPreparation/edit
    edit(data: Params.ParamDataPreparationEdit) {
        return AxiosDataPreparation.request({
            url: '/edit',
            method: 'POST',
            data: Object.assign({}, data),
            headers: { 'Content-Type': 'application/json' }
        })
    },
    // 删除
    delete(dataPreparationSourceId: string) {
        return AxiosDataPreparation.request({
            url: `/delete/${dataPreparationSourceId}`,
            method: 'GET',
            headers: { 'Content-Type': 'application/json' }
        })
    },
}

/**************************************************************************************************/
/**************************************数据准备-数据源配置管理**************************************/
/**************************************************************************************************/
const AxiosDataSourceConfigTeam = webAxiosCreate({
    paramsSerializer: params => qs.stringify(params, { arrayFormat: 'brackets' }),
    baseURL: `${context}/dataSourceConfigTeam`
})
export namespace ResponseDataSourceConfigTeam {
    // 团队接口
    export interface Team {
        label: string;
        teamId: string;
        teamName: string;
        organizationId: string;
    }

    // 组织接口
    export interface Organization {
        label: string;
        organizationId: string;
        organizationName: string;
        teams?: Team[];
    }

    // 数据源权限:数据接口
    export interface DataSource {
        dataPreparationSourceId: string;
        teamId: string;
        dataPreparationSourceName: string;
        preparationSourceDesc: string;
        dataPreparationSourceType: string;
        ipAddress: string;
        port: number;
        accountName: string;
        password: string;
        creatTime: string;
        updateTime: string;
        valiFlag: number;
    }

    // 数据源权限:分页数据接口
    export interface DataSourcePagination {
        records: DataSource[];
        total: number;
        size: number;
        current: number;
        orders: any[];
        searchCount: boolean;
        pages: number;
    }

    // 用户信息接口
    export interface UserInfo {
        userId: string;
        userName: string;
        institutionalFramework: string;
        accountName: string;
    }
}
export const ApiDataSourceConfigTeam = {
    // 列表
    listTree() {
        return AxiosDataSourceConfigTeam.request<any, ResponseDataSourceConfigTeam.Organization[]>({
            url: '/listTree',
            method: 'GET',
            headers: { 'Content-Type': 'application/json' }
        })
    },
    // 保存
    save(data: Params.ParamDataSourceConfigTeamSave) {
        return AxiosDataSourceConfigTeam.request<any, string>({
            url: '/save',
            method: 'POST',
            data: Object.assign({}, data),
            headers: { 'Content-Type': 'application/json' }
        })
    },
    // 删除
    delete(id: string) {
        return AxiosDataSourceConfigTeam.request<any, boolean>({
            url: `/delete/${id}`,
            method: 'GET',
            headers: { 'Content-Type': 'application/json' }
        })
    },
    // 获取数据源权限列表
    getDataSourceList(data: Params.ParamDataSourceConfigTeamGetDataSourceList) {
        return AxiosDataSourceConfigTeam.request<any, ResponseDataSourceConfigTeam.DataSourcePagination>({
            url: '/getDataSourceList',
            method: 'POST',
            data: Object.assign({}, data),
            headers: { 'Content-Type': 'application/json' }
        })
    },
    // 获取用户列表
    userList() {
        return AxiosDataSourceConfigTeam.request<any, ResponseDataSourceConfigTeam.UserInfo[]>({
            url: '/userList',
            method: 'GET',
            headers: { 'Content-Type': 'application/json' }
        })
    }
}

/**************************************************************************************************/
/*******************************************导出所有API********************************************/
/**************************************************************************************************/
const Service = { ApiDataPreparation };
export default { Service, Params };